package com.sfc.spiderweb.rest;

import com.ebay.eis.dto.responses.FetchTokenResponses;
import com.eis.client.ApiException;
import com.eis.client.api.OAuthApi;
import com.sfc.spiderweb.entity.param.TokenParam;
import com.sfc.spiderweb.entity.vo.Result;
import com.sfc.spiderweb.exception.SystemErrorType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Api(tags = "获取Token")
@RestController
@RequestMapping(value = "/token")
@Slf4j
public class GetTokenController {

    @ApiOperation(notes = "获取Token", value = "getToken")
    @GetMapping("/getToken")
    public Result<FetchTokenResponses> getToken(@Valid TokenParam tokenParam) {
        String url = "https://api.edisebay.com/v1/api";
            String devId = "02027820";
        String secret = "d353d941955848d791be215965a1ac820203";
        log.info("\nurl={}\ndevId={}=\nsecret={}",tokenParam.getUrl(),tokenParam.getDevId(),tokenParam.getSecret());
        OAuthApi apiInstance = new OAuthApi();
        try {
            FetchTokenResponses result = apiInstance.fetchToken(tokenParam.getUrl(), tokenParam.getDevId(), tokenParam.getSecret());
            return Result.success(result);
        } catch (Exception e) {
            log.info(e.getMessage());
            return Result.fail(e);
        }
    }

}
